h = input()
if len(h) == 4:
    wow = []
    for i in range(2, 10000):
        m = 0
        for j in range(2, i):
            if i % j == 0:
                m += 1
        if m == 0:
            wow.append(i)
    a = ['0001', '0010', '0011', '0100', '0101', '0110', '0111', '1000', '1001', '1010', '1011', '1100','1101','1110','1111']
    m = 0
    for i in a:
        uwu = ' '
        for j in range(len(i)):
            if i[j] == '1':
                uwu+=h[j]
        if int(uwu) in wow:
            m = max(m, int(uwu))
    print (m)
else:
    print('0')













